package World;

public abstract class Singleton extends ASingleton {

    private boolean isDisposed;

    private static Object instance;

    public static <T> T GetInstance() {
        return (T) instance;
    }

    private static void SetInstance(Object singleton) {
        instance = singleton;
    }

    @Override
    public void Register() {
        SetInstance(this);
    }

    public boolean IsDisposed() {
        return this.isDisposed;
    }

    protected void Destroy(){}

    @Override
    public void Dispose() {
        if (this.isDisposed) {
            return;
        }
        this.isDisposed = true;
        this.Destroy();
        SetInstance(null);
    }
}
